package com.futureCloudMOM.controller.core.web.produce;

import com.futureCloudMOM.common.annotation.Log;
import com.futureCloudMOM.common.core.domain.AjaxResult;
import com.futureCloudMOM.controller.core.controller.BaseApiController;
import com.futureCloudMOM.core.domain.ProduceDispatch;
import com.futureCloudMOM.core.domain.ProduceTaskBillSub;
import com.futureCloudMOM.core.service.BasicRoutingProcessService;
import com.futureCloudMOM.core.service.ProduceTaskBillSubService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;

/**
 * 文件名 ProduceTaskBillSubController
 *
 * @since 2023/6/6 16:06
 */
@Api(tags = "生产工单(生产订单子表)")
@RestController
@RequestMapping("produce/task_bill_sub")
public class ProduceTaskBillSubController extends BaseApiController<ProduceTaskBillSub, ProduceTaskBillSub, ProduceTaskBillSubService> {

    public ProduceTaskBillSubController(ProduceTaskBillSubService service) {
        super(service);
    }

    @Autowired
    private BasicRoutingProcessService basicRoutingProcessService;

    @Log(title = "生产工单下派")
    @ApiOperation("生产工单下派")
    @PostMapping("/dispatch")
    public AjaxResult dispatch(@RequestBody ProduceDispatch dto) {
        service.dispatch(dto);
        return success();
    }

    @Log(title = "获取模具加工时长")
    @ApiOperation("获取模具加工时长")
    @PostMapping("/dispatch/process_time")
    public AjaxResult getProcessTime(
            @RequestParam("id") Long id,
            @RequestParam("produceQty") BigDecimal produceQty,
            @RequestParam("cavityQty") Integer cavityQty) {
        return success(basicRoutingProcessService.getProcessTime(id, produceQty, cavityQty));
    }

}
